<?php

namespace Home\Model;

use Think\Model;

/**
 * Description of UserInfoModel
 *
 * @author xtceetg
 */
class UserInfoModel extends Model {

    protected $tableName = "user_add_info";

    public function getByUserInfo($uid) {
        return $this->query("select * from " . $this->tableName . " where uid='" . $uid . "'");
    }

    public function addEmail($uid, $email) {
        if ($this->getByUserInfo($uid)) {
            $data['email'] = $email;
            //$data['token_exptime'] = time() + 60 * 60 * 24; //过期时间为24小时后 
            //$data['token'] = $token;
            return $this->where("uid='" . $uid . "'")->save($data);
        } else {
            $data['uid'] = $uid;
            $data['email'] = $email;
            //$data['token_exptime'] = time() + 60 * 60 * 24; //过期时间为24小时后 
            //$data['token'] = $token;
            return $this->data($data)->add();
        }
    }

    public function check_email($email) {
        if (!preg_match('/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/', $email)) {
            return false;
        } else {
            return true;
        }
    }

}
